{% extends 'saltstack/saltstack.html' %}
{% block title %}执行系统命令{% endblock %}


{% block main %}
        <div class="tab-content">
                <div class="tab-pane fade in active">
                    <div class="row">
                    <br>
                        <form action="/saltstack/cmd_exec/{{ salt_server.id }}/" method="post" role="form">
                        <div class="col-lg-4">
                            <ul>
                            <div class="row">
                                    <div class="form-group">
                                        <h3 style="color:red">{{info}}</h3>
                                         <label for="minions_up">Minion组</label>
                                        <select class="form-control" name="group" id="groupSelect2">
                                            <option  value="{{ group }}">--{{ group }}--</option>
                                            {% for group in minion_group %}
                                                <option>{{ group.groupname }}</option>
                                            {% endfor %}
                                        </select>
                                         <select style="background-color: black;color: green" name="minion" class="form-control" size="10"  id="minions_up" >
                                             {% for minion in minions %}
                                                 <option value="{{ minion }}">{{ minion }}</option>
                                             {% endfor %}
                                         </select>

                                        <label for="minions_up">Command</label>
                                        <input class="form-control" type="text" value="{{arg}}" id="arg" name="arg">
                                        <input class="btn btn-primary btn-xs" type="submit" value="执行  ">
                                     </div>
                                </div>
                            </ul>
                        </div>
                        <div class="col-lg-1"></div>
                        <div class="col-lg-8">
                            <ul>
                            <div class="form-group">
                                <label style="color: green">执行结果：</label>
                                <textarea rows="18" style="background-color: black;color: green" class="form-control">[root@salt-master ~]#{% for key, value in cmd_exec_result.items %}
{{ key }}:
{{ value }}
{% endfor %}</textarea>
                            </div>
                            </ul>
                        </div>
                        </form>
                    </div>
                </div>
            </div>

    {% block scripts %}
        <script src="/static/js/jquery-1.8.3.min.js"  type="text/javascript"></script>
        <script>
              $("#groupSelect2").change(function(){
                var group=$(this).children('option:selected').val();
                $.get("/saltstack/get_minion/{{salt_server.id}}/",{'group':group}, function(data){
                    var array = eval(data);
                    var minions_up = $("#minions_up");
                    $("option",minions_up).remove();

                    for (var i = 0; i < array.length; i++) {
                        $("#minions_up").append("<option>" + array[i] + "</option>");
	                }
                })
              });
        </script>
    {% endblock %}
{% endblock %}